package com.app.lxx.pregnancyberth.widge;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.app.lxx.pregnancyberth.ui.entity.AddDeviceEntity;

/**
 * Created by Lxx on 2019/3/22.
 * 使用SharedPreferences储存数据
 */
public class SharedPreferencesUtils {

    private String ISFRISt = "ISFRISt";
    private String HOUSEID = "HOUSEID";
    private String BEDID = "BEDID";
    private String USERID = "USERID";
    private String BABYID = "BABYID";
    @SuppressWarnings("unused")
    private Context mContext = null;
    private SharedPreferences sharedPreferences = null;

    public SharedPreferencesUtils(Context context) {
        if (context != null) {
            mContext = context;
            sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        }
    }

    /**
     * 第一次打开APP信息
     *
     * @param frist
     */
    public void saveFristOpenInfo(String frist) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString(ISFRISt, frist);
        prefsEditor.commit();
    }

    public String getFristOpenInfo() {
        return sharedPreferences.getString(ISFRISt, "");
    }

    /**
     * 用户信息
     *
     * @param dataBean
     */
    public void saveUserLoginInfo(AddDeviceEntity.DataBean dataBean) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString(HOUSEID, dataBean.getHouse_id() + "");
        prefsEditor.putString(BEDID, dataBean.getBed_id() + "");
        prefsEditor.commit();
    }

    public String getUserHouseID() {
        return sharedPreferences.getString(HOUSEID, "");
    }

    public String getUserBedID() {
        return sharedPreferences.getString(BEDID, "");
    }

    /**
     * 床位name信息
     **/
    public void saveUserNameInfo(String HouseName, String BedName) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString("HouseName", HouseName);
        prefsEditor.putString("BedName", BedName);
        prefsEditor.commit();
    }

    public String getHouseName() {
        return sharedPreferences.getString("HouseName", "");
    }

    public String getBedName() {
        return sharedPreferences.getString("BedName", "");
    }


    /**
     * 保存用户ID
     *
     * @param UserID
     */
    public void saveUserID(String UserID) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString(USERID, UserID);
        prefsEditor.commit();
    }

    public String getUserID() {
        return sharedPreferences.getString(USERID, "");
    }

    /**
     * 保存BabyID
     *
     * @param babyID
     */
    public void saveBabyID(String babyID) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString(BABYID, babyID);
        prefsEditor.commit();
    }

    public String getBabyID() {
        return sharedPreferences.getString(BABYID, "");
    }

    /**
     * 保存定位信息
     *
     * @param mapInfo
     */
    public void saveMapInfo(String mapInfo) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString("MAPINFO", mapInfo);
        prefsEditor.commit();
    }

    public String getMapInfo() {
        return sharedPreferences.getString("MAPINFO", "");
    }

    public void saveBindingIpAddress(String ipAddress) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString("ADDRESS", ipAddress);
        prefsEditor.commit();
    }

    public String getBindingIpAddress() {
        return sharedPreferences.getString("ADDRESS", "");
    }


    /**
     * 保存服务信息
     **/
    public void saveLinPhonData(Bundle linphoneInfo) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString("serviceIp", linphoneInfo.getString("serviceIp"));
        prefsEditor.putString("serviceDq", linphoneInfo.getString("serviceDq"));
        prefsEditor.putString("serviceZh", linphoneInfo.getString("serviceZh"));
        prefsEditor.putString("serviceMm", linphoneInfo.getString("serviceMm"));
        prefsEditor.commit();
    }

    public String getLinPhonDataIp() {
        return sharedPreferences.getString("serviceIp", "");
    }

    public String getLinPhonDataDq() {
        return sharedPreferences.getString("serviceDq", "");
    }

    public String getLinPhonDataZh() {
        return sharedPreferences.getString("serviceZh", "");
    }

    public String getLinPhonDataMm() {
        return sharedPreferences.getString("serviceMm", "");
    }

    /**
     * 保存喜报信息
     */
    public void saveXiBaoData(String id, boolean starts) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putBoolean("xibaozt_"+id, starts);
        prefsEditor.commit();
    }


    public boolean getXiBaoDataZt(String id) {
        return sharedPreferences.getBoolean("xibaozt_"+id, false);
    }

    public void saveServiceIp(String serviceIp) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString("SERVICEHTTPURL", serviceIp);
        prefsEditor.commit();
    }

    public String getServiceIp() {
        return sharedPreferences.getString("SERVICEHTTPURL", "");
    }

    public void saveBindNurseUser(String NurseIp) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString("BindNurseUser", NurseIp);
        prefsEditor.commit();
    }

    public String getBindNurseUser() {
        return sharedPreferences.getString("BindNurseUser", "");
    }


}
